Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
@wordpress/dom
Advanced tools
DOM utilities module for WordPress.
Install the module
npm install @wordpress/dom --save
Get the rectangle for the selection in a container.
Parameters
Window
: The window of the selection.Returns
DOMRect | null
: The rectangle.Check whether the current document has a selection. This includes focus in input fields, textareas, and general rich-text selection.
Parameters
Document
: The document to check.Returns
boolean
: True if there is selection, false if not.Check whether the current document has selected text. This applies to ranges of text in the document, and not selection inside <input>
and <textarea>
elements.
See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
Parameters
Document
: The document to check.Returns
boolean
: True if there is selection, false if not.Check whether the current document has any sort of (uncollapsed) selection. This includes ranges of text across elements and any selection inside textual <input>
and <textarea>
elements.
Parameters
Document
: The document to check.Returns
boolean
: Whether there is any recognizable text selection in the document.Object grouping focusable
and tabbable
utils under the keys with the same name.
Gets all files from a DataTransfer object.
Parameters
DataTransfer
: DataTransfer object to inspect.Returns
File[]
: An array containing all files.Returns the closest positioned element, or null under any of the conditions of the offsetParent specification. Unlike offsetParent, this function is not limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).
Related
Parameters
Node
: Node from which to find offset parent.Returns
Node | null
: Offset parent.Get schema of possible paths for phrasing content.
Related
Parameters
[string]
: Set to "paste" to exclude invisible elements and sensitive data.Returns
Partial<ContentSchema>
: Schema.Get the rectangle of a given Range. Returns null
if no suitable rectangle can be found.
Parameters
Range
: The range.Returns
DOMRect?
: The rectangle.Given a DOM node, finds the closest scrollable container node or the node itself, if scrollable.
Parameters
Element | null
: Node from which to start.?string
: Direction of scrollable container to search for ('vertical', 'horizontal', 'all'). Defaults to 'vertical'.Returns
Element | undefined
: Scrollable container node, if found.Given two DOM nodes, inserts the former in the DOM as the next sibling of the latter.
Parameters
Node
: Node to be inserted.Node
: Node after which to perform the insertion.Returns
void
:Recursively checks if an element is empty. An element is not empty if it contains text or contains elements with attributes such as images.
Parameters
Element
: The element to check.Returns
boolean
: Whether or not the element is empty.Check whether the contents of the element have been entirely selected. Returns true if there is no possibility of selection.
Parameters
HTMLElement
: The element to check.Returns
boolean
: True if entirely selected, false if not.Detects if element is a form element.
Parameters
Element
: The element to check.Returns
boolean
: True if form element and false otherwise.Check whether the selection is horizontally at the edge of the container.
Parameters
HTMLElement
: Focusable element.boolean
: Set to true to check left, false for right.Returns
boolean
: True if at the horizontal edge, false if not.Check whether the given element is an input field of type number.
Parameters
Node
: The HTML node.Returns
node is HTMLInputElement
: True if the node is number input.Find out whether or not the given node is phrasing content.
Related
Parameters
Node
: The node to test.Returns
boolean
: True if phrasing content, false if not.Whether the element's text direction is right-to-left.
Parameters
Element
: The element to check.Returns
boolean
: True if rtl, false if ltr.Parameters
Node
:Returns
boolean
: Node is text contentCheck whether the given element is a text field, where text field is defined by the ability to select within the input, or that it is contenteditable.
See: https://html.spec.whatwg.org/#textFieldSelection
Parameters
Node
: The HTML element.Returns
node is HTMLElement
: True if the element is an text field, false if not.Check whether the selection is vertically at the edge of the container.
Parameters
HTMLElement
: Focusable element.boolean
: Set to true to check top, false for bottom.Returns
boolean
: True if at the vertical edge, false if not.Places the caret at start or end of a given element.
Parameters
HTMLElement
: Focusable element.boolean
: True for end, false for start.Places the caret at the top or bottom of a given element.
Parameters
HTMLElement
: Focusable element.boolean
: True for bottom, false for top.[DOMRect]
: The rectangle to position the caret with.Given a DOM node, removes it from the DOM.
Parameters
Node
: Node to be removed.Returns
void
:Given a schema, unwraps or removes nodes, attributes and classes on HTML.
Parameters
string
: The HTML to clean up.import('./clean-node-list').Schema
: Schema for the HTML.boolean
: Whether to clean for inline mode.Returns
string
: The cleaned up HTML.Given two DOM nodes, replaces the former with the latter in the DOM.
Parameters
Element
: Node to be removed.Element
: Node to be inserted in its place.Returns
void
:Replaces the given node with a new node with the given tag name.
Parameters
Element
: The node to replacestring
: The new tag name.Returns
Element
: The new node.Strips scripts and on* attributes from HTML.
Parameters
string
: HTML to sanitize.Returns
string
: The sanitized HTML.Unwrap the given node. This means any child nodes are moved to the parent.
Parameters
Node
: The node to unwrap.Returns
void
:Wraps the given node with a new node with the given tag name.
Parameters
Element
: The node to insert.Element
: The node to wrap.This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by WordPress as well as other software projects.
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main contributor guide.
FAQs
DOM utilities module for WordPress.
We found that @wordpress/dom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.